package org.znxs.znagent_s.config;

import jakarta.annotation.Resource;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbacks;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.znxs.znagent_s.agent.tools.QueryUserTool;
import org.znxs.znagent_s.agent.tools.TerminateTool;
import org.znxs.znagent_s.agent.tools.UserInputQueue;
import org.znxs.znagent_s.rag.tools.*;
import org.znxs.znagent_s.rag.tools.webSearch.ExaWebSearchTool;
import org.znxs.znagent_s.rag.tools.webSearch.GoogleWebSearchTool;
import org.znxs.znagent_s.rag.tools.webSearch.SearchApiSearchTool;
import org.znxs.znagent_s.rag.tools.webSearch.ZhipuWebSearchTool;

import java.util.concurrent.BlockingQueue;

/**
 * 注册所有的Agent 工具
 */
@Configuration
public class ToolRegistration {

    // searchApi apikey
    @Value("${com.search-api.api-key}")
    private String searchApiKey;

    // zhipu apikey
    @Value("${com.zhipu.api-key}")
    private String zhipuApiKey;

    // exa apikey
    @Value("${com.exa.api-key}")
    private String exaApiKey;

    // google apikey
    @Value("${com.google.api-key}")
    private String googleApiKey;

    @Resource
    private QueryUserTool queryUserTool;


    @Bean
    public ToolCallback[] allTools() {
        FileOperationTool fileOperationTool = new FileOperationTool();
        SearchApiSearchTool searchApiSearchTool = new SearchApiSearchTool(searchApiKey);
        WebScrapingTool webScrapingTool = new WebScrapingTool();
        ResourceDownloadTool resourceDownloadTool = new ResourceDownloadTool();
        TerminalOperationTool terminalOperationTool = new TerminalOperationTool();
        PDFGenerationTool pdfGenerationTool = new PDFGenerationTool();
        TerminateTool terminateTool = new TerminateTool();
//        QueryToUserTool queryToUserTool = new QueryToUserTool();
        BingSearchImgTool bingSearchImgTool = new BingSearchImgTool();
        SaveAsMarkdownTool saveAsMarkdownTool = new SaveAsMarkdownTool();
        ZhipuWebSearchTool zhipuWebSearchTool = new ZhipuWebSearchTool(zhipuApiKey);
        ExaWebSearchTool exaWebSearchTool = new ExaWebSearchTool(exaApiKey);
        GoogleWebSearchTool googleWebSearchTool = new GoogleWebSearchTool(googleApiKey);
        // 通过 ToolCallbacks 工具回调类的from方法，把所有工具的实体类加载到ToolCallback[]中
        // 它将各种不同的工具类转换为统一的 ToolCallback 数组，使系统能够以一致的方式处理它们。
        return ToolCallbacks.from(
                fileOperationTool,
                searchApiSearchTool,
                webScrapingTool,
                resourceDownloadTool,
                terminalOperationTool,
                pdfGenerationTool,
                terminateTool,
//                queryToUserTool,
                bingSearchImgTool,
                saveAsMarkdownTool,
//                zhipuWebSearchTool,
                exaWebSearchTool,
                googleWebSearchTool,
                queryUserTool
        );
    }

}